package com.greenold.Balance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.greenold.common.annotation.Log;
import com.greenold.common.core.controller.BaseController;
import com.greenold.common.core.domain.AjaxResult;
import com.greenold.common.enums.BusinessType;
import com.greenold.Balance.domain.Balance;
import com.greenold.Balance.service.IBalanceService;
import com.greenold.common.utils.poi.ExcelUtil;
import com.greenold.common.core.page.TableDataInfo;

/**
 * 余额查询Controller
 * 
 * @author ruoyi
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/balance/balance")
public class BalanceController extends BaseController
{
    @Autowired
    private IBalanceService balanceService;

    /**
     * 查询余额查询列表
     */
    @PreAuthorize("@ss.hasPermi('balance:balance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Balance balance)
    {
        startPage();
        List<Balance> list = balanceService.selectBalanceList(balance);
        return getDataTable(list);
    }

    /**
     * 导出余额查询列表
     */
    @PreAuthorize("@ss.hasPermi('balance:balance:export')")
    @Log(title = "余额查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Balance balance)
    {
        List<Balance> list = balanceService.selectBalanceList(balance);
        ExcelUtil<Balance> util = new ExcelUtil<Balance>(Balance.class);
        util.exportExcel(response, list, "余额查询数据");
    }

    /**
     * 获取余额查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('balance:balance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(balanceService.selectBalanceById(id));
    }

    /**
     * 新增余额查询
     */
    @PreAuthorize("@ss.hasPermi('balance:balance:add')")
    @Log(title = "余额查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Balance balance)
    {
        return toAjax(balanceService.insertBalance(balance));
    }

    /**
     * 修改余额查询
     */
    @PreAuthorize("@ss.hasPermi('balance:balance:edit')")
    @Log(title = "余额查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Balance balance)
    {
        return toAjax(balanceService.updateBalance(balance));
    }

    /**
     * 删除余额查询
     */
    @PreAuthorize("@ss.hasPermi('balance:balance:remove')")
    @Log(title = "余额查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(balanceService.deleteBalanceByIds(ids));
    }
}
